草庐IT

JavaBeans 比较

全部标签

c# - 将泛型与可能是值或引用类型的 null 进行比较?

publicvoidDoFoo(Tfoo)whereT:ISomeInterface{//possiblecompareofvaluetypewith'null'.if(foo==null)thrownewArgumentNullException("foo");}我故意只检查null,因为我不想限制ValueType等于它的default(T)。我的代码以这种方式编译和工作得很好(ReSharper提示,但CodeAnalysis没有)。虽然我确实想知道:是否有更标准的方法来处理这种情况?是否有可能由此引发问题?当我调用并传入一个值类型时,幕后到底发生了什么?

c# - 将泛型与可能是值或引用类型的 null 进行比较?

publicvoidDoFoo(Tfoo)whereT:ISomeInterface{//possiblecompareofvaluetypewith'null'.if(foo==null)thrownewArgumentNullException("foo");}我故意只检查null,因为我不想限制ValueType等于它的default(T)。我的代码以这种方式编译和工作得很好(ReSharper提示,但CodeAnalysis没有)。虽然我确实想知道:是否有更标准的方法来处理这种情况?是否有可能由此引发问题?当我调用并传入一个值类型时,幕后到底发生了什么?

c# - 使用 LINQ 通过一个属性比较两个列表

假设我有以下内容:classWidget1{publicintTypeID{get;set;}publicstringColor{get;set;}}classWidget2{publicintTypeID{get;set;}publicstringBrand{get;set;}}privatevoidtest(){Listwidgets1=newList();Listwidgets2=newList();Listwidgets1_in_widgets2=newList();//somecodeheretopopulatewidgets1andwidgets2foreach(Widge

c# - 使用 LINQ 通过一个属性比较两个列表

假设我有以下内容:classWidget1{publicintTypeID{get;set;}publicstringColor{get;set;}}classWidget2{publicintTypeID{get;set;}publicstringBrand{get;set;}}privatevoidtest(){Listwidgets1=newList();Listwidgets2=newList();Listwidgets1_in_widgets2=newList();//somecodeheretopopulatewidgets1andwidgets2foreach(Widge

c# - 字符串比较 null 和 empty 是否相等

使用C#和.NET3.5,处理这种情况的最佳方法是什么。我有数百个字段可以从各种来源(主要是字符串)进行比较。有时源将字符串字段返回为null,有时返回为空。当然,有时字段中会有文本。我当前对strA!=strB的比较并没有削减它,因为strA为null而strB为"",例如。我知道我可以执行string.IsNullOrEmpty,这会导致双重比较和一些丑陋。有没有更好的方法来处理这个问题?我想到了扩展方法,但你不能扩展运算符。我想我正在寻找一种性感的方式来做到这一点。 最佳答案 不会消除额外的潜在比较,但对于性感因素,您可以使用

c# - 字符串比较 null 和 empty 是否相等

使用C#和.NET3.5,处理这种情况的最佳方法是什么。我有数百个字段可以从各种来源(主要是字符串)进行比较。有时源将字符串字段返回为null,有时返回为空。当然,有时字段中会有文本。我当前对strA!=strB的比较并没有削减它,因为strA为null而strB为"",例如。我知道我可以执行string.IsNullOrEmpty,这会导致双重比较和一些丑陋。有没有更好的方法来处理这个问题?我想到了扩展方法,但你不能扩展运算符。我想我正在寻找一种性感的方式来做到这一点。 最佳答案 不会消除额外的潜在比较,但对于性感因素,您可以使用

c# - .NET Framework 的字符串比较中的错误

这是对任何comparisonsort的要求工作,底层订单运算符是transitiveandantisymmetric.在.NET中,某些字符串并非如此:staticvoidCompareBug(){stringx="\u002D\u30A2";//orjust"-ア"ifcharsetallowsstringy="\u3042";//orjust"あ"ifcharsetallowsConsole.WriteLine(x.CompareTo(y));//positiveoneConsole.WriteLine(y.CompareTo(x));//positiveoneConsole.W

c# - .NET Framework 的字符串比较中的错误

这是对任何comparisonsort的要求工作,底层订单运算符是transitiveandantisymmetric.在.NET中,某些字符串并非如此:staticvoidCompareBug(){stringx="\u002D\u30A2";//orjust"-ア"ifcharsetallowsstringy="\u3042";//orjust"あ"ifcharsetallowsConsole.WriteLine(x.CompareTo(y));//positiveoneConsole.WriteLine(y.CompareTo(x));//positiveoneConsole.W

c# - 使用 == 比较两个结构

我正在尝试在C#中使用等号(==)比较两个结构。我的结构如下:publicstructCisSettings:IEquatable{publicintGain{get;privateset;}publicintOffset{get;privateset;}publicintBright{get;privateset;}publicintContrast{get;privateset;}publicCisSettings(intgain,intoffset,intbright,intcontrast):this(){Gain=gain;Offset=offset;Bright=brigh

c# - 使用 == 比较两个结构

我正在尝试在C#中使用等号(==)比较两个结构。我的结构如下:publicstructCisSettings:IEquatable{publicintGain{get;privateset;}publicintOffset{get;privateset;}publicintBright{get;privateset;}publicintContrast{get;privateset;}publicCisSettings(intgain,intoffset,intbright,intcontrast):this(){Gain=gain;Offset=offset;Bright=brigh